home *** CD-ROM | disk | FTP | other *** search
- type
- keyRec = record
- key theKey : string;
- theVal : string;
- endRecord
- endType
-
- var
- session : string = '';
- year : word;
- month : word;
- day : word;
- dayOfWeek : word;
- date : string;
- ordFile : text;
- order : text;
- ARec : keyRec;
- items : table of keyRec;
- prices : table of keyRec;
- shipping : string;
- totalShipping : real;
- payment : string;
- fee : real;
- grandTotal : real;
- currentOrder : real;
- tempS : string;
- totalOrder : real;
- endVar
-
- function intToStr(i : longint) : string;
- var
- s : string;
- endVar
- str(i : 0 : 0, s);
- return s;
- endProc
-
- function strToReal(s : string) : real;
- var
- r : real;
- endVar
- val(s, r);
- strToReal := r;
- endProc
-
- function realToStr(r : real) : string;
- var
- s : string;
- endVar
- str(r : 0 : 2, s);
- return s;
- endProc
-
- procedure main
- session := fieldParm('SessionID');
- if ((session = '') or (session = '*SeSiOnId*'))
- printError;
- return;
- endif
- getDate(year, month, day, dayOfWeek);
- date := intToStr(month) + intToStr(day) + intToStr(year);
- assign(ordFile, date + '.ord');
- if (append(ordFile) <> 0)
- if (rewrite(ordFile) <> 0)
- printError;
- return;
- endif
- endif
- writeln(ordFile, session);
- close(ordFile);
- tempS := copy(session, 1, length(session) - 4) + '.frm';
- assign(order, tempS);
- if (rewrite(order) <> 0)
- printError;
- return;
- endif
- loadTable(items, session);
- loadTable(prices, 'prices.db');
-
- if (getRealItem('TotalOrder') = 0)
- printNothingOrdered;
- return;
- endif
-
- writeTitle('Order');
- printBoth('Order ID ' + session, "<h1>", "</h1>");
- tempS := 'Date : ' + intToStr(month) + '/' + intToStr(day) + '/' + intToStr(year);
- printBoth(tempS, '<br>', '<br>');
-
- writeln(order);
- printBoth("Thank you for your order, here is a copy of the order that was processed", "<br>", "<br>");
- writeln(order);
- printCompany; { generated }
- writeln(order);
- printBoth("Please send me the following products :", "<br>", "");
- printProducts; { generated }
- printShippingCharges;
- printPaymentCharges;
- printGrandTotal;
- printPayment;
- printBoth("Shipping information", "<br><B>", "</B>");
- printShipping;
- printBoth("Billing information", "<br><B>", "</B>");
- printBilling;
- printContact;
- printComments;
-
- close(order);
-
- printContinue;
- endProc
-
- procedure printError
- writeTitle('Script Error');
- writeln('Script executed with wrong parameters');
- endProc
-
- procedure printBoth(message : string; before : string; after : string);
- writeln(order, message);
- write(before);
- write(message);
- write(after);
- endProc
-
- procedure printShipping;
- tempS := fieldParm('SHIPNAME');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('SHIPTITLE');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('SHIPCOMPANY');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('SHIPADDR1');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('SHIPADDR2');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('SHIPCITY');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('SHIPSTATE');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('SHIPZIP');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('SHIPCOUNTRY');
- printBoth(tempS, "<br>", "");
- endProc
-
- procedure printBilling;
- if (fieldParm('BILLNAME') = '')
- printBoth("Same as shipping", "<br>", "<br>");
- else
- tempS := fieldParm('BILLNAME');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('BILLTITLE');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('BILLCOMPANY');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('BILLADDR1');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('BILLADDR2');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('BILLCITY');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('BILLSTATE');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('BILLZIP');
- printBoth(tempS, "<br>", "");
- tempS := fieldParm('BILLCOUNTRY');
- printBoth(tempS, "<br>", "");
- endif
- endProc
-
- procedure printContact;
- printBoth("Contact Information", "<B>", "</B>");
- tempS := "Tel : " + fieldParm('PHONE');
- printBoth(tempS, "<br>", "");
- tempS := "Fax : " + fieldParm('FAX');
- printBoth(tempS, "<br>", "");
- tempS := "EMail1 : " + fieldParm('EMAIL1');
- printBoth(tempS, "<br>", "");
- tempS := "EMail2 : " + fieldParm('EMAIL2');
- printBoth(tempS, "<br>", "");
- endProc
-
- function getRealPrice(AKey : string) : real;
- ARec.theKey := AKey;
- setKeysFromRecord(prices, ARec);
- if (readRecord(prices, ARec))
- return strToReal(ARec.theVal);
- else
- return 0;
- endif
- endProc
-
- function getRealItem(AKey : string) : real;
- ARec.theKey := AKey;
- setKeysFromRecord(items, ARec);
- if (readRecord(items, ARec))
- return strToReal(ARec.theVal);
- else
- return 0;
- endif
- endProc
-
-
- procedure printShippingCharges
- printBoth("Shipping Charges", "<br><b>", "</b>");
- Shipping := "S_" + fieldParm('SHIPOPT');
- TotalShipping := (getRealPrice(Shipping + "3") * getRealItem('TotalProducts')) +
- getRealPrice(Shipping + "1") + (getRealPrice(Shipping + "2") * getRealItem('TotalWeight'));
- tempS := "Total for " + fieldParm('SHIPOPT') + ' : $' + realToStr(TotalShipping);
- printBoth(tempS, "<br>", "<br>");
- endProc
-
- procedure printPayment
- printBoth("Payment Method", "<br><b>", "</b>");
- tempS := "Payment by " + fieldParm('PAYOPT');
- printBoth(tempS, "<br>", "");
- if (getRealPrice(payment + "1") = 1)
- tempS := "PO/WT number " + fieldParm('CARDNUM');
- printBoth(tempS, "<br>", "");
- else if (getRealPrice(payment + "1") = 2)
- tempS := "Card number : " + fieldParm('CARDNUM');
- printBoth(tempS, "<br>", "");
- tempS := "Name on card : " + fieldParm('NAMEONCARD');
- printBoth(tempS, "<br>", "");
- tempS := "Expiration date : " + fieldParm('EXPRDATE');
- printBoth(tempS, "<br>", "");
- endif
- endif
- endProc
-
- procedure printPaymentCharges
- payment := 'P_' + fieldParm('PAYOPT');
- fee := getRealPrice(payment + '2');
- if (fee <> 0)
- tempS := "Payment fee is $" + realToStr(fee);
- printBoth(tempS, "<br>", "<br>");
- endif
- endProc
-
- procedure printGrandTotal;
- grandTotal := fee + getRealItem('TotalOrder') + TotalShipping;
- tempS := "Total payment is $" + realToStr(GrandTotal);
- printBoth(tempS, "<br>", "<br>");
- endProc
-
- procedure printComments
- if (fieldParm('COMMENTS') <> '')
- printBoth("Comments", "<br><b>", "</b>");
- tempS := fieldParm('COMMENTS');
- printBoth(tempS, "<br>", "");
- endif
- endProc
-
- procedure printNothingOrdered
- writeTitle('Order Error');
- writeHeading(1, 'Order Error');
- write('No products were ordered!<br>');
- write('Please press the Back button, specify what products you want to');
- write('order by clicking the Submit button under an item's quantity table,');
- write('after you have specified the number of items in the table!');
- write('<HR>');
- endProc
-